const express = require('express');
const router = express.Router();
const data = [];

/**
 * @param {Object} options
 * @param {} options.codes
 * @throws {Error}
 * @return {Promise}
 */
for(let i = 1; i < 51; i++)
    data.push({
        id: `${i}`,
        code: `XS2019082700-${i}`,
        dealerCode: 'string',
        dealerName: 'string',
        orderType: 1,
        transportType: 2,
        paymentType: 1,
        salesOrderPriceTerms: 2,
        status: 2,
        totalAmount: 0,
        rowVersion: 'string',
        createTime: '2020-03-05T08:29:20.933Z',
        options: [
            'update',
            'abandon',
            'submit',
            'approve',
            'operationDepartmentApprove',
            'generalManagerApprove',
        ]
    });
router.get('/', (req, res) => {
    const {pageIndex, pageSize} = req.query;
    res.json({
        message: 'ok',
        payload: {
            content: data,
            pageIndex: parseInt(pageIndex, 10),
            pageSize: parseInt(pageSize, 10),
            totalElements: 50
        }
    });
});

router.get('/lastTimeOfCBUsaleorder', (req, res) => {
    res.json({
        message: 'ok',
        payload: {
            salesOrderPriceTerms: 0,
            paymentType: 0,
            carierId: 'string',
            CarrierName: 'string',
            destinationPort: 'string',
        }
    });
});


router.get('/forSaleConfirmation', (req, res) => {
    const content = [];
    for(let i = 0; i < 100; i++)
        content.push({
            id: `2020${i}`,
            code: `2020${i}`,
            brandId: `00${i}`,
            brandCode: 'brandCode',
            brandName: 'brandName',
            dealerId: '001',
            dealerCode: 'dealerCode',
            dealerName: 'dealerName',
            currency: 1,
            tradeMethodId: 'tradeMethodId',
            tradeMethodCode: 'tradeMethodCode',
            tradeMethodName: 'tradeMethodName',
            paymentType: 1,
            transportType: 1,
            salesOrderPriceTerms: 1,
            countryOfOrigin: '中国',
            countryOfDestination: '美国',
            address: '重庆',
            contactNumber: '56465461',
            zipCode: '404000',
            productAmount: 65466465,
            batchNumber: '0020021',
            saleProformaInvoices: [
                {
                    id: '1',
                    code: 'FP001'
                }, {
                    id: '2',
                    code: 'FP002'
                }, {
                    id: '3',
                    code: 'FP003'
                },
            ]
        });
    res.json({
        message: '',
        payload: {
            content,
            totalElements: 100,
        }
    });
});

router.get('/:id/forSaleConfirmation', (req, res) => {
    const details = [];
    for(let i = 0; i < 20; i++)
        details.push({
            id: `2020${i}`,
            sourceCode: 'sourceCode',
            productGroupId: `productGroupId${i}`,
            productGroupCode: `productGroupCode${i}`,
            productGroupName: `productGroupName${i}`,
            productCode: `productCode${i}`,
            productName: `productName${i}`,
            productId: `productId${i}`,
            productCategoryId: `productCategoryId${i}`,
            productCategoryCode: `productCategoryCode${i}`,
            productCategoryName: `productCategoryName${i}`,
            quantity: 456,
            price: 131,
            totalPrice: 456454,
            taxFreePrice: 1232,
            taxFreeTotalPrice: 3123213,
            createTime: '2020-02-18T08:46:01.096Z',
            kDBomCode: 'kDBomCode',
            descriptionOfGoods: 'descriptionOfGoods'
        });
    res.json({
        message: '',
        payload: {
            details,
            totalElements: 20,
        }
    });
});
router.get('/export/forCurrentUser', (req, res) => {
    res.json({
        message: '导出成功',
        payload: 'Mock导出'
    });
});
router.put('/:id/abandon', (req, res) => {
    res.json({
        message: '作废成功'
    });
});
router.put('/:id/pass', (req, res) => {
    res.json({
        message: '审核成功'
    });
});
router.put('/:id/reject', (req, res) => {
    res.json({
        message: '驳回成功'
    });
});
router.put('/:id/finalJudgment/pass', (req, res) => {
    res.json({
        message: '终审成功'
    });
});
router.put('/:id/finalJudgment/reject', (req, res) => {
    res.json({
        message: '驳回成功'
    });
});
router.put('/:id/cancel', (req, res) => {
    res.json({
        message: '取消成功'
    });
});
router.put('/:id/submit', (req, res) => {
    res.json({
        message: '提交成功'
    });
});
router.put('/:id', (req, res) => {
    res.json({message: '修改成功'});
});
router.post('/', (req, res) => {
    res.json({
        message: '新增成功'
    });
});

router.get('/:id', (req, res) => {
    res.json({
        message: 'ok',
        payload: {
            id: '1',
            code: 'string',
            dealerId: 'dealerId',
            dealerCode: 'string',
            dealerName: 'string',
            orderType: 1,
            transportType: 1,
            paymentType: 1,
            salesOrderPriceTerms: 1,
            status: 1,
            totalAmount: 0,
            createTime: '2020-03-05T08:35:49.738Z',
            rowVersion: 'string',
            options: [
                'update',
                'abandon',
                'submit',
                'approve',
                'operationDepartmentApprove',
                'generalManagerApprove',
            ],
            brandId: 'brandId',
            carrierId: 'carrierId',
            shippingPortId: 'shippingPortId',
            tradeMethodId: 'tradeMethodId',
            tradeMethodName: 'string',
            currency: 1,
            country: 'string',
            account: 'string',
            carrierName: 'string',
            shippingPortName: 'string',
            destinationPort: 'string',
            vinYear: 0,
            deliveryDate: '2020-03-05T08:35:49.738Z',
            remark: 'string',
            creatorName: 'string',
            modifierName: 'string',
            modifyTime: '2020-03-05T08:35:49.738Z',
            submitterName: 'string',
            submitTime: '2020-03-05T08:35:49.738Z',
            abandonerName: 'string',
            abandonTime: '2020-03-05T08:35:49.738Z',
            nextApproveNumber: 1,
            details: [
                {
                    id: '1',
                    serialNums: 'string',
                    PICode: 'string1',
                    PISubmitTime: '2020-03-05T08:35:49.738Z',
                    productGroupCode: 'string',
                    productGroupName: 'string',
                    productCode: 'string',
                    productName: 'string',
                    productCategoryCode: 'string',
                    productCategoryName: 'string',
                    color: 'string',
                    engineModel: 'string',
                    transmission: 'string',
                    package: 'string',
                    newProductCategoryCode: 'string',
                    quantity: 0,
                    price: 0,
                    totalPrice: 0
                },
                {
                    id: '2',
                    serialNums: 'string',
                    PICode: 'string2',
                    PISubmitTime: '2020-03-05T08:35:49.738Z',
                    productGroupCode: 'string',
                    productGroupName: 'string',
                    productCode: 'string',
                    productName: 'string',
                    productCategoryCode: 'string',
                    productCategoryName: 'string',
                    color: 'string',
                    engineModel: 'string',
                    transmission: 'string',
                    package: 'string',
                    newProductCategoryCode: 'string',
                    quantity: 0,
                    price: 0,
                    totalPrice: 0
                }
            ]
        }
    });
});


module.exports = router;
